﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zj.OpenAuth.Domain.Core;
using Zj.OpenAuth.Domain.Interface;

namespace Zj.OpenAuth.Repository
{
    /// <summary>
    /// user repository service
    /// </summary>
    public class UserRepository : BaseRepository<User>,IUserRepository
    {
        public UserRepository(DbContext ctx)
            :base(ctx)
        {
            
        }

        public bool UpdateRoleMenu(int userId, List<UserRoleMapping> userRoles)
        {
            var urs = Context.Set<UserRoleMapping>().Where(rm => rm.UserId == userId);
            foreach (var item in urs)
            {
                Context.Set<UserRoleMapping>().Remove(item);
            }

            Context.Set<UserRoleMapping>().AddRange(userRoles);
            return Context.SaveChanges() > 0;
        }
    }
}
